package org.oslims.server.dao.hbm;

import java.util.List;

import org.hibernate.Query;
import org.oslims.domain.LabResponsible;
import org.oslims.server.dao.LabResponsibleDao;

public class HbmLabResponsibleDao extends HbmGenericDao<LabResponsible, Long> implements LabResponsibleDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<LabResponsible> findAllWithDepartments() {
		Query q = this.getSession().createQuery("select distinct l from LabResponsible l left join fetch l.departments order by l.firstName");
		return q.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LabResponsible> findAllWithDepartments(int start, int length, String sortBy, Boolean desc) {
		String sortDirection = "asc";

		if (desc)
			sortDirection = "desc";

		Query q = this.getSession().createQuery("select distinct l from LabResponsible l left join fetch l.departments order by l." + sortBy + " " + sortDirection);
		q.setFirstResult(start);
		q.setMaxResults(length);

		return q.list();
	}

}
